<template>
  <div class="hello">
    <div>Hi, 我没有任何ssr</div>

    <div @click="gotoHelloPage()">点击我触发路由跳转</div>

    下面设置一下cooke， key: test, value: hello_word

    <input v-model="cookieVal"></input>
    <div style="margin-top: 20px" @click="setCookieTest()">点击我设置cookie</div>

    <div style="margin-top: 20px">
      <div @click="getCookieTest()">查看cookie</div>
      <div style="margin-top: 10px">{{cookieVal}}</div>
    </div>

    <div style="margin-top: 20px" @click="deleteCookieTest()">删除cookie</div>

    <router-go path="/demo/helloword" @click="testClick()" target="_blank">跳转组件</router-go>
    <div @click="gogogo()">js全局跳转组件</div>

    <div style="margin-top: 20px;background-color: silver">
      <div @click="queryAgain()">查询</div>
      <div>{{res1}}</div>
    </div>
  </div>
</template>

<script>
  import {admin_auth_cookie_key, deleteCookie, getCookie, setCookie} from '../../config/cookie-process.js'
  import RouterGo from '../../components/router-go/router-go.vue'
  import {gateway_test} from '../../api/BaseRestApi'

  export default {
    name: 'foo-demo',
    components: {RouterGo},
    metaInfo: {
      title: 'foo | no ssr',
    },
    data() {
      return {
        cookieVal: '',
        res1: ''
      }
    },
    needSerialize: true,
    async created() {
      await this.queryAgain()
    },
    methods: {
      gotoHelloPage() {
        this.$router.push({name: 'demo-hello-word'})
      },
      setCookieTest() {
        let d = new Date()
        d.setTime(d.getTime() + (24 * 60 * 60 * 1000))
        setCookie(this, admin_auth_cookie_key, this.cookieVal, d)
      },
      deleteCookieTest() {
        deleteCookie(this, admin_auth_cookie_key)
      },
      getCookieTest() {
        this.cookieVal = getCookie(this, admin_auth_cookie_key)
      },
      testClick() {
        console.log('=================testClick================')
      },
      gogogo() {
        this.$go(this, '/demo/helloword', true)
      },
      async queryAgain() {
        let res = await this.$get(gateway_test)
        this.res1 = res + "---处理一下数据"
      }
    }
  }
</script>
